package cn.yj.frame.spring.event;

import cn.yj.frame.netty.NettyServer;
import cn.yj.register.RegisterConfig;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.ApplicationListener;

/**
 * 服务启动失败 移除注册
 *
 * @author 永健
 * @since 2022-01-19 09:57
 */
public class NettyApplicationStartFailListener implements ApplicationListener<ApplicationFailedEvent> {

	@Override
	public void onApplicationEvent(ApplicationFailedEvent applicationFailedEvent) {
		String host = applicationFailedEvent.getApplicationContext().getEnvironment().getProperty("spring.rpc.host");
		RegisterConfig.getInstance().logout(host);
		// 服务启动失败,移除注册中心的服务
		NettyServer.closeServer();
	}
}
